package com.jx.service;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jx.mapper.JyxmztMapper;
import com.jx.po.Jyxmzt;
import com.jx.vo.CarVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class JyxmztService extends ServiceImpl<JyxmztMapper, Jyxmzt> {

    public IPage getCars(CarVo carVo) {
        Page page = new Page();
        Wrapper<Jyxmzt> wrapper = createWrapper(carVo);
        IPage page1 = page(page, wrapper);
        return page;
    }

    public IPage getCars() {
        return page(new Page<>());

    }


    private Wrapper<Jyxmzt> createWrapper(CarVo carVo) {
        QueryWrapper<Jyxmzt> jyxmztQueryWrapper = new QueryWrapper<>();
        if (carVo == null) {
            return jyxmztQueryWrapper;
        }
        jyxmztQueryWrapper.like(StringUtils.isNotEmpty(carVo.getJylsh()), Jyxmzt.Fields.jylsh, carVo.getJylsh());
        jyxmztQueryWrapper.like(StringUtils.isNotEmpty(carVo.getHphm()), Jyxmzt.Fields.hphm, carVo.getHphm());

        jyxmztQueryWrapper.eq("jyxm", carVo.getQueryModel());
        jyxmztQueryWrapper.orderByDesc(true, "kssj");
        return jyxmztQueryWrapper;

    }
}
